package cn.tedu.csmall.order.webapi.config;

import cn.tedu.csmall.order.webapi.quartz.OrderJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail addOrder(){
        return JobBuilder.newJob(OrderJob.class)
                .withIdentity("newOder")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger addOrderTrigger(){
        CronScheduleBuilder cronSchedule
                = CronScheduleBuilder.cronSchedule("0 0/2 * 2 2 ?");
        return TriggerBuilder.newTrigger()
                .withIdentity("goAddOrder")
                .withSchedule(cronSchedule)
                .forJob(addOrder())
                .build();
    }
}
